package com.zycfc.zsf.boot.web;

import com.zycfc.zsf.boot.data.domain.*;
import java.io.*;
import org.slf4j.*;
import com.zycfc.zsf.boot.mybatis.service.*;
import org.springframework.validation.annotation.*;
import org.springframework.web.bind.annotation.*;
import com.zycfc.zsf.boot.core.web.data.*;
import io.swagger.annotations.*;
import com.zycfc.zsf.boot.core.web.annotation.*;
import com.zycfc.zsf.boot.exception.*;
import com.zycfc.zsf.boot.mybatis.page.*;
import java.util.*;

public abstract class GenericRestController<T extends BaseDomain, Pk extends Serializable> extends AbstractController
{
    protected Logger logger;
    
    public GenericRestController() {
        this.logger = LoggerFactory.getLogger((Class)this.getcalsses());
    }
    
    protected Class<?> getcalsses() {
        return this.getClass();
    }
    
    protected abstract AbstractService<T, Pk> getService();
    
    @ApiOperation(value = "\u65b0\u589e", notes = "\u65b0\u589e")
    @ZsfActionMapping({ "/add" })
    public DataResponse<?> add(@Validated @RequestBody final DataRequest<T> dataRequest) throws BaseException {
        this.getService().add((BaseDomain)dataRequest.getData());
        return (DataResponse<?>)DataResponse.succeed();
    }
    
    @ZsfActionMapping({ "/update" })
    @ApiOperation(value = "\u4fee\u6539", notes = "\u4fee\u6539")
    public DataResponse<?> update(@Validated @RequestBody final DataRequest<T> dataRequest) throws BaseException {
        this.getService().updateById((BaseDomain)dataRequest.getData());
        return (DataResponse<?>)DataResponse.succeed();
    }
    
    @ZsfActionMapping({ "/delete" })
    @ApiOperation(value = "\u5220\u9664", notes = "\u5220\u9664")
    public DataResponse<?> delete(@Validated @RequestBody final DataRequest<T> dataRequest) throws BaseException {
        this.getService().deleteById(((BaseDomain)dataRequest.getData()).getId());
        return (DataResponse<?>)DataResponse.succeed();
    }
    
    @ZsfActionMapping({ "/detail" })
    @ApiOperation(value = "\u67e5\u8be2\u660e\u7ec6", notes = "\u67e5\u8be2\u660e\u7ec6")
    public DataResponse<T> detail(@Validated @RequestBody final DataRequest<T> dataRequest) throws BaseException {
        final String a = "A:B:C";
        final T t = (T)this.getService().findOneById(((BaseDomain)dataRequest.getData()).getId());
        if (t == null) {
            throw new NotFoundException();
        }
        return (DataResponse<T>)DataResponse.succeed((Object)t);
    }
    
    @ZsfActionMapping({ "/list" })
    @ApiOperation(value = "\u67e5\u8be2\u5217\u8868", notes = "\u67e5\u8be2\u5217\u8868")
    public DataResponse<?> list(@Validated @RequestBody final DataRequest<T> dataRequest) throws BaseException {
        final List<T> list = (List<T>)this.getService().findByPage((int)dataRequest.getCurrent(), (int)dataRequest.getPageSize(), (BaseDomain)dataRequest.getData());
        final ZsfPage<T> page = (ZsfPage<T>)new ZsfPage((List)list);
        return (DataResponse<?>)DataResponse.succeed((Object)page.getList(), page.getPageNum(), page.getPageSize(), page.getTotal(), page.getPages());
    }
}
